Skip to content

refactor(server): make Conversation Render a real module - #453

Merged
spokvulcan merged 3 commits into
mainfrom
conversation-render-module
Sep 2, 2026
Merged

spokvulcan merged 3 commits into
mainfrom
conversation-render-module

Conversation

@spokvulcan

Copy link
Copy Markdown
Owner

Conversation Render existed only as a convention. Five call sites (six, it turned out) each hand-rolled the same ladder: cache eligibility, the RenderTokenCache resolve, the applyChatTemplate fallback, the merged add_generation_prompt context. The #439 bug was that shape failing, with one site wiring the wrong image list into the shared predicate.

Now it's a value. ConversationRender is built once at Request Keying from instance truth, sealed with the settled key space, enriched with the C31 base render by the leaf store, and rides the generation record to every later phase. RenderTokenSource dissolves into it. Eligibility is answered in one place, so that class of defect has nowhere to live.

Along the way: the unkeyed arm stopped threading a render nothing reads, the leaf-store measure and the abort-arm seed no longer hop through a session just to fetch a tokenizer, and the four per-file test render helpers collapsed into one shared fixture that can inject a private cache (the admission cache-path suite no longer serializes on the global).

No behavior change intended. Focused render, planner, builder and completion suites pass; Release build runs. Net -194 lines.

https://claude.ai/code/session_01NfKR27x9ZEAbwmbxpeFQkj

The streaming text row re-parsed and re-typeset the whole accumulated
answer through one ChatMarkdownView on every ~100ms publish. Profiling a
real long turn showed the main thread fully saturated during answer
streaming, 60-76% of samples inside
ResolvedStyledText.StringDrawing.sizeThatFits re-typesetting the entire
document — the same pattern PR #451 removed from the thinking row.

ChunkedStreamingMarkdown freezes completed block runs into immutable
chunk views (cuts only at blank lines outside code fences, never before
an indented continuation) so each publish re-renders only the live
tail. Seam spacing mirrors Textual's block spacing (16pt, 24pt before a
heading or thematic break). The committed row still renders the whole
text through one ChatMarkdownView, restoring full selection and
fidelity. The markdown-off live path now streams through
ChunkedStreamingText for the same reason.

After: prose streaming leaves the main thread 77-88% idle;
whole-document re-typeset is gone from the profile (4811 -> 14
samples). The remaining hot stretch is a streaming fenced code block,
whose per-run Text concatenation lives in Textual's TextBuilder —
bounded per block, out of scope here.

Claude-Session: https://claude.ai/code/session_01B9e9SmCUS6UxZfcxD9w9iA
Cleanup pass over the live-markdown chunking:

- Seam spacing is now classified once when a chunk freezes and stored on
  it, instead of re-deriving every frozen seam on every publish — the one
  O(accumulated chunks) term left in an O(tail) view (measured ~23
  calls/publish at 50KB, each an allocating Character scan).
- The Textual GitHub block-spacing literals move next to
  ChatMarkdownStyle as ChatMarkdownBlockSpacing, so a Textual bump or
  style change is checked in one place.
- LiveProseView folds into AssistantProseView(isLive:) — one owner for
  the markdown/plain branch and the plain-text modifier stack, so the
  live→committed hand-off cannot drift.
- The byte-identical index(atUTF8Offset:) helper is shared from
  ChatViewSupport instead of copied into both accumulators.
- finishLine flattened; isThematicBreak no longer re-filters the line
  per marker.

Claude-Session: https://claude.ai/code/session_01B9e9SmCUS6UxZfcxD9w9iA
Collapse the per-site render+token-cache ladders (request edge, planner
last-user re-render, leaf-store measure, admission probes, agent edge,
echo-fidelity replay) into one ConversationRender value. Eligibility is
decided once at Request Keying from instance truth, sealed with the
request's Cache Key Space, enriched with the C31 base render by the leaf
store, and carried to every later phase. RenderTokenSource dissolves
into it, so the #439 class of defect (one site wiring the wrong
ingredient into the shared predicate) is unrepresentable.

Also drops the dead render threading on the unkeyed arm, the session
hops the leaf-store measure and abort-arm seed used just to fetch a
tokenizer, and the four per-file test render helpers (now one shared
fixture that can inject a private cache, letting the admission
cache-path suite stop serializing on the global).

Claude-Session: https://claude.ai/code/session_01NfKR27x9ZEAbwmbxpeFQkj
@spokvulcan
spokvulcan merged commit 2321017 into main Sep 2, 2026
5 checks passed
spokvulcan added a commit that referenced this pull request Sep 3, 2026
…#456)

Candidate 2 from the 2026-09-02 architecture review, rebased on main
after #453 and #455 landed.

The agent chat turn and both thinking-safeguard continuations were three
hand copies inside `LLMActor` with no test reach and no progress events
on the continuation side. They are now one `RawGenerationStart` module
over a Model Session, and the agent path becomes the seam's second
consumer (ADR-0016 amendment in the diff).

What moved:
- `ModelSession` gains `prepareText` (the agent-edge tokenize verb,
composing Conversation Render's agent edge so eligibility keeps its one
spelling there), `templateMessages(for:)`, and `makeRawDecodeIterator`.
The provider gains a non-Sendable session entry for the agent's
`UserInput`.
- `LLMActor` keeps one `startRawGeneration(prompt:)`. About 300 lines
shorter.
- `DFlash2Support.rawArmIterator` is gone; the load-time pairing check
already gates the drafter.

Two behaviour changes, on purpose: continuations now preempt the
background speculative prefill, and they emit the same progress events
and DFlash2 badge the fresh turn does.

Tests: `RawGenerationStartTests` (7) over the toy session. Focused
server + agent groups green, 72 tests across 14 suites.

Manual check worth doing: an intervened turn on the 27B with the drafter
loaded should now show the DFlash2 badge on the continuation in
Activity.

Follow-up PR: move `ParoParityBenchRunner.runOnce` (the fourth copy)
onto the module after a parity run.
spokvulcan pushed a commit that referenced this pull request Sep 5, 2026
🤖 I have created a release *beep* *boop*
---


## [1.12.0](v1.11.1...v1.12.0) (2026-09-05)

### Highlights

DFlash2 speculative decoding on Qwen3.8-27B is a lot faster. On an M3 Max with the 4-bit model, decode went from 28 to 49 tok/s on a travel blog post, from 55 to 71 tok/s on code and from 77 to 98 tok/s on math word problems, against 23 tok/s without speculation. The round that drafts eight tokens and verifies them dropped from 68 ms to 54 ms: a leaner 4-bit matmul kernel for the eight-row verify pass, a dozen small kernels fused into single launches in the Qwen3.5 layers and the drafter, a fused attention route for the verify block, and a drafter head that scores only the part of the vocabulary that ever comes up. The generated text is unchanged on the prompts we track; the target model still decides every token.

One fix matters outside the benchmark: the app now sets `MLX_DYNSLICE_INPLACE` at launch, so speculative rows are written into the KV cache in place. Before, only the benchmark runner set it, and production copied the whole cache store on every such write, a cost that grew with the context.

For anyone building from source, `scripts/dflash2-bench.sh` runs a single DFlash2 pass on a frozen prompt in about 40 seconds after the build, with an optional token-for-token check against plain decoding; the prompts and the measured ledger live under `benchmarks/dflash2/`. The model catalog also gains Qwen3.8-27B in its PARO quantization with the same speculation (#461). The full list of changes follows.


### Features

* **bench:** DFlash2 acceptance research + prompt-hash, variant and prompt-file arms ([1d03aba](1d03aba))
* **bench:** DFlash2 fast bench, fixtures and ledger ([606e3db](606e3db))
* **models:** add Qwen3.8-27B PARO with DFlash2 speculation ([#461](#461)) ([d33674f](d33674f))


### Bug Fixes

* **app:** set MLX_DYNSLICE_INPLACE at launch ([98a1cda](98a1cda))


### Code Refactoring

* **agent:** one Raw Generation Start over the Model Session seam ([#456](#456)) ([4f345ee](4f345ee))
* **dflash2:** reduce the drafter to its fast path and move the pin (ADR-0061) ([#464](#464)) ([3cb640a](3cb640a))
* **server:** make Conversation Render a real module ([#453](#453)) ([2321017](2321017))
* **server:** one Completion Delivery script behind a Delivery Sink seam ([#455](#455)) ([75a9428](75a9428))


### Documentation

* add model parameters reference ([#462](#462)) ([9139e11](9139e11))
* point CLAUDE.md at the pr-title workflow's real path (fixes Docs Check) ([b0d6749](b0d6749))
* record the 2026-09-05 DFlash2 loop landing in the fork docs ([fda975b](fda975b))


### Miscellaneous Chores

* **deps:** move the mlx-swift pins to 6058402 and the vendor to 0647cf9 ([a4bff95](a4bff95))
* **deps:** re-pin mlx-swift-lm to upstream e3d4a20 ([d37fc13](d37fc13))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant